/*
 *    Copyright 2022 jacky4631 shen ji email:121659050@qq.com
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.dataoke.shoppingguide.app773026.activity.splash;

import android.content.Context;
import android.content.Intent;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.dataoke.shoppingguide.app773026.R;
import com.dataoke.shoppingguide.app773026.app.AppOperator;
import com.dataoke.shoppingguide.app773026.base.activities.BaseActivity;
import com.dataoke.shoppingguide.app773026.activity.home.MainActivity;
import com.dataoke.shoppingguide.app773026.util.AppUtil;

import butterknife.BindView;

/**
 * 启动页
 * @author: shen ji
 * @date: 2022/3/15
 * @email: 121659050@qq.com
 * @wechat: jacky4631
 */
public class SplashActivity extends BaseActivity {


    @BindView(R.id.iv_welcome)
    ImageView mWelcome;

    public static void show(Context context) {
        context.startActivity(new Intent(context, SplashActivity.class));
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        if(AppUtil.isTaoShengQian(this)) {
            mWelcome.setImageDrawable(getResources().getDrawable(R.mipmap.tsq_welcome));
        }
    }


    @Override
    protected void initData() {
        super.initData();
        AppOperator.runOnThread(() -> doMerge());
    }

    private void doMerge() {
//        // 判断是否是新版本
//        if (Setting.checkIsNewVersion(this)) {
//            // Cookie迁移
//            String cookie = JKJApplication.getInstance().getProperty("cookie");
//            if (!TextUtils.isEmpty(cookie)) {
//                JKJApplication.getInstance().removeProperty("cookie");
//                User user = AccountHelper.getUser();
//                user.setCookie(cookie);
//                JKJApplication.reInit();
//            }
//        }

        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 完成后进行跳转操作
        redirectTo();
    }

    private void redirectTo() {
//        if (JKJSharedPreference.getInstance().isFirstInstall()) {
//            IntroduceActivity.show(this);
//        } else {
            MainActivity.show(this);
//        }
        finish();
    }

}
